package com.basics.framework.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Swagger2的接口配置
 *
 * @author basics
 */
@Configuration
@EnableSwagger2
@EnableKnife4j
@Import(BeanValidatorPluginsConfiguration.class)
public class SwaggerConfig {
    /** 系统基础配置 */
    @Autowired
    private BasicsConfig basicsConfig;

    /**
     * 创建API
     */
    @Bean(value = "defaultApi")
    public Docket defaultApi() {
        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo())
                        // 分组名称
                        .groupName("2.X版本").select()
                        // 这里指定Controller扫描包路径
                        .apis(RequestHandlerSelectors.basePackage("com.basics")).paths(PathSelectors.any()).build();
    }

    /**
     * 添加摘要信息
     */
    private ApiInfo apiInfo() {
        // 用ApiInfoBuilder进行定制
        return new ApiInfoBuilder()
                        // 设置标题
                        .title("标题：业主-小程序端-管理系统_接口文档")
                        // 描述
                        .description("描述：用于管理集团旗下公司的人员信息,具体包括XXX,XXX模块...")
                        // 作者信息
                        .contact(new Contact(basicsConfig.getName(), null, null))
                        // 版本
                        .version("版本号:" + basicsConfig.getVersion()).build();
    }
}
